package com.tancire.system.service.impl;

import java.util.List;
import javax.annotation.Resource;

import com.alibaba.fastjson2.JSONObject;
import com.tancire.common.core.redis.RedisCache;
import com.tancire.common.utils.DateUtils;
import org.springframework.stereotype.Service;
import com.tancire.system.mapper.AppModuleMapper;
import com.tancire.system.domain.AppModule;
import com.tancire.system.service.IAppModuleService;

import static com.tancire.common.constant.Constants.APP_CONFIG_KEY;

/**
 * APP页面配置Service业务层处理
 *
 * @author chenchao
 * @date 2024-01-15
 */
@Service
public class AppModuleServiceImpl implements IAppModuleService {

    @Resource
    private AppModuleMapper appModuleMapper;

    @Resource
    private RedisCache redisCache;

    /**
     * 查询APP页面配置
     *
     * @param id APP页面配置主键
     * @return APP页面配置
     */
    @Override
    public AppModule selectAppModuleById(Long id) {
        return appModuleMapper.selectAppModuleById(id);
    }

    /**
     * 查询APP页面配置列表
     *
     * @param appModule APP页面配置
     * @return APP页面配置
     */
    @Override
    public List<AppModule> selectAppModuleList(AppModule appModule) {
        return appModuleMapper.selectAppModuleList(appModule);
    }

    /**
     * 新增APP页面配置
     *
     * @param appModule APP页面配置
     * @return 结果
     */
    @Override
    public int insertAppModule(AppModule appModule) {
        appModule.setCreateTime(DateUtils.getNowDate());
        return appModuleMapper.insertAppModule(appModule);
    }

    /**
     * 修改APP页面配置
     *
     * @param appModule APP页面配置
     * @return 结果
     */
    @Override
    public int updateAppModule(AppModule appModule) {
        appModule.setUpdateTime(DateUtils.getNowDate());
        return appModuleMapper.updateAppModule(appModule);
    }

    /**
     * 批量删除APP页面配置
     *
     * @param ids 需要删除的APP页面配置主键
     * @return 结果
     */
    @Override
    public int deleteAppModuleByIds(Long[] ids) {
        return appModuleMapper.deleteAppModuleByIds(ids);
    }

    /**
     * 删除APP页面配置信息
     *
     * @param id APP页面配置主键
     * @return 结果
     */
    @Override
    public int deleteAppModuleById(Long id) {
        return appModuleMapper.deleteAppModuleById(id);
    }

    /**
     * 刷新redis
     */
    @Override
    public void refreshRedis() {
        List<AppModule> allList = appModuleMapper.selectAllModule();
        redisCache.setCacheObject(APP_CONFIG_KEY, JSONObject.toJSONString(allList));
    }
}
